<?php
namespace app\admin\controller;

use think\Controller;
use think\Db;
use think\Session;

class Home extends Controller
{
    public function index()
    {
        $user_name = input('user_name', null);
        $pass_word = input('password', null);
        if ($user_name && $pass_word) {
            $pass_word = md5($pass_word);
            $user_info = Db::table('super_user')
                ->where([
                    'user_name' => $user_name,
                    'password' => $pass_word,
                ])
                ->find();
            if (!$user_info) {
                $this->error('密码错误');
            } else {
                session('user_name', $user_name);
                session('pass_word', $pass_word);
                $this->success('true');
            }
        } else {
            if (Session::get('user_name') && Session::get('pass_word')) {
                $user_info = Db::table('super_user')
                    ->where([
                        'user_name' => Session::get('user_name'),
                        'password' => Session::get('pass_word'),
                    ])
                    ->find();
                if (!$user_info) {
                    $this->error('状态失效');
                }
            } else {
                $this->error('请登录');
            }
        }
        $clover_number = Db::table('name')
            ->count('id');
        $new_efi_number = Db::table('new_efi')
            ->count('id');
        $new_efi_number_icon = ($new_efi_number) ? 'fas fa-frown' : 'fas fa-smile-beam';
        $new_efi_number = ($new_efi_number) ? $new_efi_number . '个 clover 未审核' : '没有未审核的';
        return $this->fetch(null, ['clover_number' => $clover_number, 'new_efi_number' => [0 => $new_efi_number_icon, 1 => $new_efi_number], 'date_time' => date('Y-m-d H:i:s')]);
    }
}
